# models/keywords.py
"""
Author: didiplus
Description: 关键词规则模型定义
Date: 2025-08-20 20:37:07
LastEditors: didiplus
LastEditTime: 2025-08-20 20:37:08
FilePath: /WeChatBot/app/models/keywords.py
Version: 1.0
"""


from sqlalchemy import Column, String, Text, Integer, BigInteger, Boolean, ForeignKey
from sqlalchemy.orm import relationship
from .base import BaseModel

class KeywordRuleModel(BaseModel):
    """
    关键词规则模型
    用于存储用户定义的关键词匹配规则
    """
    __tablename__ = "keyword_rules"
    
    #: 关键词内容
    keyword = Column(String(255), nullable=False, index=True, comment="关键词内容")
    
    #: 匹配后的响应内容
    response = Column(Text, nullable=False, comment="匹配后的响应内容")
    
    #: 优先级，数值越小优先级越高
    priority = Column(Integer, default=1, nullable=False, comment="优先级，数值越小优先级越高")
    
    #: 是否区分大小写，默认不区分
    case_sensitive = Column(Boolean, default=False, nullable=False, comment="是否区分大小写")
    
    #: 是否精确匹配，默认模糊匹配
    exact_match = Column(Boolean, default=False, nullable=False, comment="是否精确匹配")
    
    #: 是否激活，默认激活
    is_active = Column(Boolean, default=True, nullable=False, comment="是否激活")
    
    #: 用户ID，关联用户表
    user_id = Column(Integer, ForeignKey("users.id"), nullable=False, index=True, comment="用户ID，关联用户表")
    
    #: 规则描述
    description = Column(String(500), nullable=True, comment="规则描述")
    
    # 关联关系
    user = relationship("User", back_populates="keyword_rules")